package cn.sdhuijin.healthexam.activity;

import java.io.File;
import java.io.FileReader;
import java.util.Properties;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Util;

/**
 * 健康体检详细信息
 * 
 * 
 * @author houyuchun
 * 
 */
public class HealthExamInfoActivity extends AbstractControlActivity implements
		OnClickListener {

	private TextView xindiantu; // 手术

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_health_exam_info);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		// 获取传递过来的sql语句
		String fileName = intent.getStringExtra("filename");
		initTextView();
		setTextViewValue(fileName);
		setButtonListener(this, R.id.btn_back);
	}

	@Override
	public void onClick(View v) {
		int clickId = (Integer) v.getId();
		switch (clickId) {
		case R.id.btn_back:
			finish();
			break;
		default:
			break;
		}
	}

	/**
	 * TextView初始化赋值
	 */
	private void initTextView() {

		addTextView(R.id.txt_user_name, "姓名");
		addTextView(R.id.txt_identify_num, "身份证号");
		addTextView(R.id.txt_exam_date, "体检日期");
		addTextView(R.id.txt_duty_doctor, "责任医生");
		addTextView(R.id.txt_zhengzhuang, "症状_content");
		addTextView(R.id.txt_zhengzhuang_qita, "症状-其他");
		addTextView(R.id.txt_tiwen, "体温");
		addTextView(R.id.txt_mailv, "脉率");
		addTextView(R.id.txt_huxipinlv, "呼吸频率");
		addTextView(R.id.txt_zuocegaoya, "左侧高压");
		addTextView(R.id.txt_zuocediya, "左侧低压");
		addTextView(R.id.txt_youcegaoya, "右侧高压");
		addTextView(R.id.txt_youcediya, "右侧低压");
		addTextView(R.id.txt_shengao, "身高");
		addTextView(R.id.txt_tizhong, "体重");
		addTextView(R.id.txt_yaowei, "腰围");
		addTextView(R.id.txt_tizhizhishu, "体质指数");

		addTextView(R.id.txt_jkztzwpg, "健康状态_content");
		addTextView(R.id.txt_shzlnlzwpg, "生活自理能力_content");
		addTextView(R.id.txt_renzhigongneng, "认知功能_content");

		addTextView(R.id.txt_jyzljcdf, "简易智力状态检查评分");
		addTextView(R.id.txt_yypfjcdf, "老人年抑郁检查评分");

		addTextView(R.id.txt_qingganzhuangtai, "情感状态_content");
		addTextView(R.id.txt_tiyuduanlian, "锻炼频率_content");

		addTextView(R.id.txt_meiciduanliansj, "每次锻炼时间");
		addTextView(R.id.txt_jianchidlsj, "坚持锻炼时间");
		addTextView(R.id.txt_duanlianfangshi, "锻炼方式");

		addTextView(R.id.txt_yinshixiguan, "饮食习惯_content");

		addTextView(R.id.txt_xiyanzhuangkuang, "吸烟状况_content");

		addTextView(R.id.txt_rixiyanliang, "日吸烟量");
		addTextView(R.id.txt_kaishixynl, "开始吸烟年龄");
		addTextView(R.id.txt_jieyannl, "戒烟年龄");

		addTextView(R.id.txt_yinjiupinlv, "饮酒频率_content");

		addTextView(R.id.txt_riyinjiuliang, "日饮酒量");

		addTextView(R.id.txt_shifoujiejiu, "是否戒酒_content");

		addTextView(R.id.txt_jiejiunl, "戒酒年龄");
		addTextView(R.id.txt_kaishiyjnl, "开始饮酒年龄");

		addTextView(R.id.txt_xiongjiu, "近一年内是否曾醉酒_content");

		addTextView(R.id.txt_jiejiuzl, "饮酒种类_content");
		addTextView(R.id.txt_jiejiuzl_qita, "其他酒类");

		addTextView(R.id.txt_zybwhysjcs, "职业病危害因素接触史_content");
		addTextView(R.id.txt_dwzlfcfhcs, "毒物种类粉尘防护措施_content");
		addTextView(R.id.txt_fswzfhcs, "放射物质防护措施_content");

		addTextView(R.id.txt_gongzhongcysj, "工种从业时间");

		addTextView(R.id.txt_wlysfhcs, "物理因素防护措施_content");
		addTextView(R.id.txt_hxwzfhcs, "化学物质防护措施_content");
		addTextView(R.id.txt_qtfhcs, "其他防护措施_content");
		addTextView(R.id.txt_kouchun, "口唇_content");
		addTextView(R.id.txt_chilie, "齿列_content");
		addTextView(R.id.txt_yanbu, "咽部_content");

		addTextView(R.id.txt_zuoyanshili, "左眼视力");
		addTextView(R.id.txt_youyanshili, "右眼视力");
		addTextView(R.id.txt_zuoyanjzshili, "左眼矫正视力");
		addTextView(R.id.txt_youyanjzshili, "右眼矫正视力");

		addTextView(R.id.txt_tingli, "听力_content");
		addTextView(R.id.txt_yundonggongneng, "运动功能_content");
		addTextView(R.id.txt_yandi, "眼底_content");
		addTextView(R.id.txt_pifu, "皮肤_content");
		addTextView(R.id.txt_gongmo, "巩膜_content");
		addTextView(R.id.txt_gongmo_qita, "巩膜-其他");
		addTextView(R.id.txt_linbajie, "淋巴结_content");
		addTextView(R.id.txt_linbajie_qita, "淋巴结-其他");

		addTextView(R.id.txt_tongzhuangxiong, "桶状胸_content");
		addTextView(R.id.txt_luoyin, "罗音_content");
		addTextView(R.id.txt_luoyin_qita, "罗音-其他");
		addTextView(R.id.txt_huxiyin, "呼吸音_content");
		addTextView(R.id.txt_xinlvci, "心率");
		addTextView(R.id.txt_xinlv, "心律_content");
		addTextView(R.id.txt_zayin, "杂音_content");
		addTextView(R.id.txt_yatong, "压痛_content");
		addTextView(R.id.txt_baokuai, "包块_content");
		addTextView(R.id.txt_ganda, "肝大_content");
		addTextView(R.id.txt_pida, "脾大_content");
		addTextView(R.id.txt_yidongxingzy, "移动性浊音_content");
		addTextView(R.id.txt_xiazhishuizhong, "下肢水肿_content");
		addTextView(R.id.txt_zubeidongmai, "足背动脉搏动_content");

		addTextView(R.id.txt_gangmenzhizhen, "肛门指诊_content");
		addTextView(R.id.txt_gangmenzhizhen_qita, "肛门指诊-其他");
		addTextView(R.id.txt_ruxian, "乳腺_content");
		addTextView(R.id.txt_ruxian_qita, "乳腺-其他");
		addTextView(R.id.txt_waiyin, "外阴_content");
		addTextView(R.id.txt_yindao, "阴道_content");
		addTextView(R.id.txt_gongjing, "宫颈_content");
		addTextView(R.id.txt_gongti, "宫体_content");
		addTextView(R.id.txt_fuke_fujian, "附件_content");

		addTextView(R.id.txt_fuke_qita, "查体其他");
		addTextView(R.id.txt_xuehongdanbai, "血红蛋白");
		addTextView(R.id.txt_baixibao, "白细胞");
		addTextView(R.id.txt_xuexiaoban, "血小板");
		addTextView(R.id.txt_xuechanggui_qita, "血常规其他");

		addTextView(R.id.txt_niaodanbai, "尿蛋白");
		addTextView(R.id.txt_niaotang, "尿糖");
		addTextView(R.id.txt_niaojiongti, "尿酮体");
		addTextView(R.id.txt_niaoqianxue, "尿潜血");
		addTextView(R.id.txt_niaochanggui_qita, "尿常规其他");
		addTextView(R.id.txt_kongfuxuetang, "空腹血糖");

		addTextView(R.id.txt_xindiantu, "心电图_content");
		xindiantu = (TextView) findViewById(R.id.txt_xindiantu);

		addTextView(R.id.txt_niaoweiliangbdb, "尿微量白蛋白");

		addTextView(R.id.txt_dabianqianxue, "大便潜血_content");

		addTextView(R.id.txt_tanghuahongbdb, "糖化血红蛋白");
		addTextView(R.id.txt_yiganbiaomianky, "乙型肝炎表面抗原_content");

		addTextView(R.id.txt_xueqinggbzam, "血清谷丙转氨酶");
		addTextView(R.id.txt_xueqinggczam, "血清谷草转氨酶");
		addTextView(R.id.txt_baidanbai, "白蛋白");
		addTextView(R.id.txt_zongdanhongsu, "总胆红素");
		addTextView(R.id.txt_jiehedanhongsu, "结合胆红素");
		addTextView(R.id.txt_xueqingjigan, "血清肌酐");
		addTextView(R.id.txt_xueniaosudan, "血尿素氮");
		addTextView(R.id.txt_xueyanongdu, "血钾浓度");
		addTextView(R.id.txt_xuenanongdu, "血钠浓度");

		addTextView(R.id.txt_zongdanguchun, "总胆固醇");
		addTextView(R.id.txt_ganyousanzhi, "甘油三酯");
		addTextView(R.id.txt_xueqingdmd, "血清低密度脂蛋白胆固醇");
		addTextView(R.id.txt_xueqinggmd, "血清高密度脂蛋白胆固醇");
		addTextView(R.id.txt_fuzhujc_qita, "辅助检查其他");

		addTextView(R.id.txt_xiongbuxx, "胸部X线片_content");
		addTextView(R.id.txt_bchao, "B超_content");
		addTextView(R.id.txt_gongjingtupian, "宫颈涂片_content");
		addTextView(R.id.txt_pinghezhi, "平和质_content");
		addTextView(R.id.txt_qixuzhi, "气虚质_content");
		addTextView(R.id.txt_yangxuzhi, "阳虚质_content");
		addTextView(R.id.txt_yinxuzhi, "阴虚质_content");
		addTextView(R.id.txt_danshizhi, "痰湿质_content");
		addTextView(R.id.txt_shirezhi, "湿热质_content");
		addTextView(R.id.txt_xueyuzhi, "血瘀质_content");
		addTextView(R.id.txt_qiyuzhi, "气郁质_content");
		addTextView(R.id.txt_tebingzhi, "特秉质_content");

		addTextView(R.id.txt_naoxueguanjb, "脑血管疾病_content");
		addTextView(R.id.txt_naoxueguanjb_qita, "脑血管疾病-其他");
		addTextView(R.id.txt_shenzangjb, "肾脏疾病_content");
		addTextView(R.id.txt_shenzangjb_qita, "肾脏疾病-其他");
		addTextView(R.id.txt_xinzangjb, "心脏疾病_content");
		addTextView(R.id.txt_xinzangjb_qita, "心脏疾病-其他");
		addTextView(R.id.txt_xueguanjb, "血管疾病_content");
		addTextView(R.id.txt_xueguanjb_qita, "血管疾病-其他");
		addTextView(R.id.txt_yanbujb, "眼部疾病_content");
		addTextView(R.id.txt_yanbujb_qita, "眼部疾病-其他");

		addTextView(R.id.txt_jingshenxtjb, "神经系统疾病名称");
		addTextView(R.id.txt_qitaxtjb, "其他系统疾病名称");

		addTextView(R.id.txt_zhuyuanriqi, "入院日期");
		addTextView(R.id.txt_chuyuanriqi, "出院日期");
		addTextView(R.id.txt_zhuyuanyuanyin, "住院原因");
		addTextView(R.id.txt_yiliaojigoumc, "医疗机构名称");
		addTextView(R.id.txt_zhuyuanshibah, "住院史病案号");
		addTextView(R.id.txt_jianchuangriqi, "建床日期");
		addTextView(R.id.txt_chechuangriqi, "撤床日期");
		addTextView(R.id.txt_jiatingbcyy, "家庭病床原因");
		addTextView(R.id.txt_jtb_yiliaojigoumc, "家庭病床医疗机构名称");
		addTextView(R.id.txt_jiatingbah, "家庭病案病案号");

		addTextView(R.id.txt_yaowumingcheng1, "药物名称1");
		addTextView(R.id.txt_yongfa1, "用法1");
		addTextView(R.id.txt_yongliang1, "用量1");
		addTextView(R.id.txt_yongyaoshijian1, "用药时间1");
		addTextView(R.id.txt_fuyaoycx1, "服药依从性1");

		addTextView(R.id.txt_yaowumingcheng2, "药物名称2");
		addTextView(R.id.txt_yongfa2, "用法2");
		addTextView(R.id.txt_yongliang2, "用量2");
		addTextView(R.id.txt_yongyaoshijian2, "用药时间2");
		addTextView(R.id.txt_fuyaoycx2, "服药依从性2");

		addTextView(R.id.txt_yaowumingcheng3, "药物名称3");
		addTextView(R.id.txt_yongfa3, "用法3");
		addTextView(R.id.txt_yongliang3, "用量3");
		addTextView(R.id.txt_yongyaoshijian3, "用药时间3");
		addTextView(R.id.txt_fuyaoycx3, "服药依从性3");

		addTextView(R.id.txt_yaowumingcheng4, "药物名称4");
		addTextView(R.id.txt_yongfa4, "用法4");
		addTextView(R.id.txt_yongliang4, "用量4");
		addTextView(R.id.txt_yongyaoshijian4, "用药时间4");
		addTextView(R.id.txt_fuyaoycx4, "服药依从性4");

		addTextView(R.id.txt_yaowumingcheng5, "药物名称5");
		addTextView(R.id.txt_yongfa5, "用法5");
		addTextView(R.id.txt_yongliang5, "用量5");
		addTextView(R.id.txt_yongyaoshijian5, "用药时间5");
		addTextView(R.id.txt_fuyaoycx5, "服药依从性5");

		addTextView(R.id.txt_yaowumingcheng6, "药物名称6");
		addTextView(R.id.txt_yongfa6, "用法6");
		addTextView(R.id.txt_yongliang6, "用量6");
		addTextView(R.id.txt_yongyaoshijian6, "用药时间6");
		addTextView(R.id.txt_fuyaoycx6, "服药依从性6");

		addTextView(R.id.txt_yufangjzmc1, "预防接种名称1");
		addTextView(R.id.txt_jiezhongriqi1, "预防接种日期1");
		addTextView(R.id.txt_jiezhongjigou1, "预防接种机构1");

		addTextView(R.id.txt_yufangjzmc2, "预防接种名称2");
		addTextView(R.id.txt_jiezhongriqi2, "预防接种日期2");
		addTextView(R.id.txt_jiezhongjigou2, "预防接种机构2");

		addTextView(R.id.txt_jiankangpingjia, "健康评价_content");
		addTextView(R.id.txt_jiankangpingjia_yc1, "健康评价-异常1");
		addTextView(R.id.txt_jiankangpingjia_yc2, "健康评价-异常2");
		addTextView(R.id.txt_jiankangpingjia_yc3, "健康评价-异常3");
		addTextView(R.id.txt_jiankangpingjia_yc4, "健康评价-异常4");

		addTextView(R.id.txt_jiankangzhidao, "健康指导_content");

		addTextView(R.id.txt_weixianyinsukongzhi, "危险因素控制_content");
		addTextView(R.id.txt_weixianyinsukongzhi_qita, "危险因素控制-其他");

	}

	/**
	 * 读取对应文件，设置各个控件值
	 * 
	 * @param fileName
	 *            文件名称
	 */
	private void setTextViewValue(String fileName) {
		try {
			File f = new File(Environment.getExternalStorageDirectory()
					.getPath() + "/health/" + fileName + ".txt");
			if (f.exists()) {
				controlManager.setPropertiesPath(f.getAbsolutePath());
				controlManager.toControl();
				Properties prop = new Properties();
				prop.load(new FileReader(f.getAbsolutePath()));
				xindiantu.setText(getPropertiesValueByNames(prop, "心电图"));

			} else {
				this.toastInformation(R.string.record_deleted);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param prop
	 * @param strings
	 * @return
	 */
	public String getPropertiesValueByNames(Properties prop, String str) {
		StringBuffer buffer = new StringBuffer();
		try {
			if (str.equals("心电图")
					&& Util.allIsNotEmpty(prop.getProperty("心电图_content"))) {
				buffer.append(prop.getProperty("心电图_content"));
				if (prop.getProperty("心电图_content").equals("异常")) {
					buffer.append("-");
					buffer.append(prop.getProperty("心电图-异常"));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return buffer.toString();
	}
}
